﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebDocDB.Managers;
using WebDocDB.Models;

namespace WebDocDB.Controllers
{
    public class HomeController : Controller
    {
        private IAccountManager accountManager;

        public HomeController(IAccountManager accountManager)
        {
            this.accountManager = accountManager;
        }

        public ActionResult Index()
        {
            Session.Clear();
            var uavm = new UserAccountViewModel();
            return View(uavm);
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Index(UserAccountViewModel model)
        {
            if (ModelState.IsValid)
            {
                accountManager.SaveAccountSettings(model.AccountUrl, model.AccountKey);

                return RedirectToAction("Index", "Databases");
            }

            return View(model);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}